package bysj.service;

import bysj.dao.GraduateProjectDao;
import bysj.domain.GraduateProject;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public final class GraduateProjectService {
	private GraduateProjectDao graduateProjectDao= GraduateProjectDao.getInstance();
	private static GraduateProjectService graduateProjectService = new GraduateProjectService();
	
	//Singleton
	private GraduateProjectService(){}

	public static GraduateProjectService getInstance(){
		return graduateProjectService;
	}

	public Collection<GraduateProject> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		Collection<GraduateProject> graduateProjects = graduateProjectDao.findAll(connection,conditionList,pagination);
		JdbcHelper.close(connection);
		return graduateProjects;
	}

	public GraduateProject find(Integer id) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		GraduateProject graduateProject = graduateProjectDao.find(id,connection);
		JdbcHelper.close(connection);
		return graduateProject;
	}

	public boolean update(GraduateProject graduateProject) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean updated = graduateProjectDao.update(graduateProject,connection);
		JdbcHelper.close(connection);
		return updated;
	}

	public boolean add(GraduateProject graduateProject) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean added = graduateProjectDao.add(graduateProject,connection);
		JdbcHelper.close(connection);
		return added;
	}

	public boolean delete(Integer id) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean deleted = graduateProjectDao.delete(id,connection);
		JdbcHelper.close(connection);
		return deleted;
	}
	
}
